- /* sxmshift.cpp by K.Tsuru */
- // function ID = 506 BRADIX
- /********************
- SDecimal class
- bit shift x --> x*2^p
- *********************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- SDecimal& SDecimal::BitShift(long p){
- if(!p || !Sign()) return *this;
- long r, top, f0, shift;
- int err = 0;
- fType mult, div;
- if(p > 0){
- shift = p/(long)BRADIX_BITS;
- r = p - shift*(long)BRADIX_BITS;// r >= 0
- mult = 1 << (int)r;
- top = (long)aTail - shift; // top figure position after shift.
- if(top < 0) err = 1;
- else if( top == 0 ){
- f0 = (long)figure(0)*mult;
- if(f0 >= BRADIX) err = 1; // first figure >= BRADIX
- }
- if(err) SetError(OVERFLOW_ERR, "SX BitShift", 506);
- if(shift) ShiftArray(-(int)shift);
- if(r) XsMult(*this, mult, *this); // mult > 1
- return *this;
- }
- // p < 0
- shift = -p/(long)BRADIX_BITS;
- r = -(BRADIX_BITS*shift + p);
- div = 1 << (int)r;
-
- if( shift + (long)aTail >= (long)CurrentMaxSize() ) SetZero();
- else {
- if(shift) ShiftArray((int)shift);
- if(r) XsDiv(*this, div, *this);
- }
- return *this;
- }
sxmshift.cpp : last modifiled at 2017/03/13 14:32:02(1,073 bytes)
created at 2015/12/22 16:09:56
The creation time of this html file is 2017/10/27 15:45:59 (Fri Oct 27 15:45:59 2017).